package code1.double_pointer;

/**
 * 原题链接：https://leetcode.cn/problems/remove-element/
 */
public class P27 {

    //双指针法移除元素
    public int removeElement(int[] nums, int val) {
        int slowIndex=0;
        for(int fastIndex=0;fastIndex<nums.length;fastIndex++){
            if(nums[fastIndex]!=val){       //快指针指向的元素不等于val就加入新数组中
                nums[slowIndex++]=nums[fastIndex];
            }
        }
        return slowIndex;
    }
}
